from typing import List


class Solution:
    def imageSmoother(self, img: List[List[int]]) -> List[List[int]]:
        m = len(img)
        n = len(img[0])
# leetcode submit region end(Prohibit modification and deletion)
        """
        方法二：简化了一下方法一的步骤，其实是一个意思
        """
        res= [[0]*n for _ in range(m)]
        # 记录偏移量
        direction = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]
        for i in range(m):
            for j in range(n):
                sum = img[i][j]
                count = 1
                for x,y in direction:
                    # 如果偏移之后还存在，那么计算
                    if 0<=i+x<m and 0<=j+y<n:
                        sum+=img[i+x][j+y]
                        count+=1
                # //效果也是向下取整
                res[i][j] = sum//count
        return res